﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Common;
//using System.Web.Script.Serialization;

namespace Web.Helpers.jqGridHelpers
{
    /// <summary>
    /// Helper class to assist building jqGrid Filter
    /// </summary>
    public class jqGridFilter
    {
        #region Constructors

        /// <summary>
        /// Default constructor
        /// </summary>
        public jqGridFilter()
        {
        }

        #endregion

        #region Properties

        private string _groupOp;
        /// <summary>
        /// Group Operand
        /// </summary>
        public string groupOp
        {
            get { return _groupOp; }
            set { _groupOp = value; }
        }

        private RulesSet[] _rules;
        /// <summary>
        /// Set of Rules
        /// </summary>
        public RulesSet[] rules
        {
            get { return _rules; }
            set { _rules = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        public class RulesSet
        {
            private string _field;
            /// <summary>
            /// Field
            /// </summary>
            public string field
            {
                get { return _field; }
                set { _field = value; }
            }

            private string _op;
            /// <summary>
            /// Operand
            /// </summary>
            public string op
            {
                get { return _op; }
                set { _op = value; }
            }

            private string _data;
            /// <summary>
            /// Value
            /// </summary>
            public string data
            {
                get { return _data; }
                set { _data = value; }
            }
        }

        #endregion

        #region Methods

        /// <summary>
        /// Returns a jqGridFilter object, derived from given string
        /// </summary>
        /// <param name="jSON"></param>
        /// <returns></returns>
        public static jqGridFilter ConvertFromJSON(string jSON)
        {
            //JavaScriptSerializer oSerializer = new JavaScriptSerializer();
            //jqGridFilter obj = oSerializer.Deserialize<jqGridFilter>(jSON);
            //return obj;
            return Formatter.JSON<jqGridFilter>.Deserialize(jSON);
        }

        #endregion
    }

}
